home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 18 / develop 18 code / PwrPC 601 µs Timer / Timer.s < prev   
Encoding:
Text File  |  1994-03-10  |  3.6 KB  |  138 lines  |  [TEXT/MPS ]

  1. cr1:        equ    1
  2.  
  3.     ;
  4.     ; File:            Timer.s
  5.     ;
  6.     ; Copyright:    © 1993-1994 by Apple Computer, Inc., all rights reserved.
  7.     ;
  8.     ; This sample contains three routines for using the RTC (Real Time Clock) on
  9.     ; PowerPC 601 chip.  
  10.     ;
  11.     ; WARNING
  12.     ; IMPORTANT!!:  The RTC is only available on the 601 and this code will crash if
  13.     ; run on any other PowerPC chips.  Do not use this code in a shipping product.
  14.     ;
  15.     ; This code is written from the asmSample in the PPC SDK
  16.     ;
  17.     
  18.     
  19. linkageArea:        set 24    ; constant comes from the PowerPC Runtime Architecture Document
  20. CalleesParams:        set    32    ; always leave space for GPR's 3-10
  21. CalleesLocalVars:    set 0    ; MicroSecondsRTC doesn't have any
  22. numGPRs:            set 0    ; num volitile GPR's (GPR's 13-31) used by MicroSecondsRTC
  23. numFPRs:            set 0    ; num volitile FPR's (FPR's 14-31) used by MicroSecondsRTC
  24.  
  25. spaceToSave:    set linkageArea + CalleesParams + CalleesLocalVars + 4*numGPRs + 8*numFPRs  
  26.  
  27.  
  28.     ; Need to export both the function descriptor and an entry point for
  29.     ; MicroSecondsRTC.  The function entry point doesn't have to be a csect
  30.     ; name - it can be a regular label.  Since PPCC puts a '.' in front of
  31.     ; function names, the entry point label's name must begin with a '.'
  32.     
  33.     export MicroSecondsRTC[DS]
  34.     export .MicroSecondsRTC[PR]
  35.     
  36.     ; create a TOC entry for the the function.  This is 
  37.     
  38.     toc MicroSecondsRTC, MicroSecondsRTC[DS]
  39.  
  40.     ; The function descriptor contains definitions used for runtime linkage
  41.     ; of the function.  The address of the function entry point must be in 
  42.     ; the first longword.  The address of the start of the TOC for the  
  43.     ; module that contains the function (use the predefined PPCAsm
  44.     ; global tc0) must be in the second longword.  The third longword 
  45.     ; contains the environment pointer, which is not used by C and so is set
  46.     ; to 0.
  47.     
  48.     csect    MicroSecondsRTC[DS]
  49.         dc.l    .MicroSecondsRTC[PR]        
  50.         dc.l    TOC[tc0]
  51.         dc.l    0
  52.  
  53.     
  54.     ; This is the actual code of the MicroSecondsRTC function 
  55.     
  56.     csect    .MicroSecondsRTC[PR]
  57.  
  58. ; PROLOGUE: called routine's responsibilities
  59. ;         mflr    r0                        ; Get link register
  60. ;        stw        r0, 0x0008(SP)            ; Store the link resgister on the stack
  61. ;        stwu    SP, -spaceToSave(SP)    ; skip over the stack space where the caller
  62.                                         ; might have saved stuff
  63.  
  64.     ; We are a leaf function so we don't need to do the prologue or epilogue
  65.     
  66. ; FUNCTION BODY
  67. load_RTC:
  68.         mfspr    r3, 4                    ; dc.l     0x7C6402A6,  mfspr    r3, RTCU
  69.         mfspr    r4, 5                    ; dc.l     0x7C8502A6,  mfspr    r4, RTCL
  70.         mfspr    r5, 4                    ; dc.l     0x7CA402A6,  mfspr    r5, RTCU
  71.                 
  72.         cmpw     r3, r5
  73.         bne     load_RTC
  74.                 
  75.         li        r6, 1000
  76.         divwu     r4, r4, r6
  77.         
  78.         lis        r5,15                    ; Multiply the seconds times 1,000,000
  79.         ori        r5,r5,0x4240
  80.         mullw    r3,r3,r5
  81.         
  82.         add        r3, r3, r4
  83.         
  84. ; EPILOGUE:    return sequence
  85. ;        lwz        r0, 0x8+spaceToSave(SP)    ; Get the saved link register
  86. ;        addic    SP, SP, spaceToSave        ; Reset the stack pointer
  87. ;        mtlr    r0                        ; Reset the link register
  88.         blr                                ; return via the link register
  89.  
  90.  
  91.  
  92.  
  93.     
  94.     export FetchRTCU[DS]
  95.     export .FetchRTCU[PR]
  96.     
  97.     ; create a TOC entry for the the function.  This is 
  98.     
  99.     toc FetchRTCU, FetchRTCU[DS]
  100.     
  101.     csect    FetchRTCU[DS]
  102.         dc.l    .FetchRTCU[PR]        
  103.         dc.l    TOC[tc0]
  104.         dc.l    0
  105.  
  106.     
  107.     ; This is the actual code of the FetchRTCU function 
  108.     
  109.     csect    .FetchRTCU[PR]
  110.  
  111. ; FUNCTION BODY
  112.         mfspr    r3, 4                    ; dc.l     0x7C6402A6,  mfspr    r3, RTCU
  113.         blr                                ; return via the link register
  114.  
  115.  
  116.  
  117.     
  118.     export FetchRTCL[DS]
  119.     export .FetchRTCL[PR]
  120.     
  121.     ; create a TOC entry for the the function.  This is 
  122.     
  123.     toc FetchRTCL, FetchRTCL[DS]
  124.     
  125.     csect    FetchRTCL[DS]
  126.         dc.l    .FetchRTCL[PR]        
  127.         dc.l    TOC[tc0]
  128.         dc.l    0
  129.  
  130.     
  131.     ; This is the actual code of the FetchRTCL function 
  132.     
  133.     csect    .FetchRTCL[PR]
  134.  
  135. ; FUNCTION BODY
  136.         mfspr    r3, 5                    ; mfspr    r3, RTCL
  137.         blr                                ; return via the link register
  138.